Change in openvpn[master]: route: extended logic to omit gateway when unnecessary
A message that is not in the archive (sent off-list or not yet received): gerrit.1722331476000.I87777e74b1fd34781e1d72c9f994eb84f39d800c@...2715...
Attention is currently required from: flichtenheld, plaisthos.
Hello plaisthos, flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
to review the following change.
Change subject: route: extended logic to omit gateway when unnecessary
......................................................................
route: extended logic to omit gateway when unnecessary
Extracted and extended the logic behind 'gateway_needed' both in add_route() and add_route_ipv6(). Other than checking the dev-type, special routes and if the gateway is on-link,
- set gateway_needed to true if the vpn instance is a multipoint server and DCO is enabled.
- set gateway_needed to false if the gateway is in the vpn subnet. Additionally, extended support for these checks and conditions to DARWIN and BSD-based operating systems.
These changes ensure that the gateway is only included when necessary, optimizing route configuration and potentially reducing redundant route entries.
---
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/route.c
M src/openvpn/route.h
M src/openvpn/tun.c
M src/openvpn/tun.h
7 files changed, 420 insertions(+), 256 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/21/721/1
src/openvpn/forward.c +1 -1
@@ -421,7 +421,7 @@ check_add_routes_action(struct context *c, const bool errors) { bool route_status = do_route(&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP );int flags = (errors ?ISC_ERRORS :0 ); flags |= (!route_status ?ISC_ROUTE_ERRORS :0 );
src/openvpn/init.c +10 -9
@@ -1134,7 +1134,7 @@tuncfg (options->dev, options->dev_type, options->dev_node, options->persist_mode, options->username, options->groupname, &options->tuntap_options, - ctx); + ctx, options->mode ==MODE_SERVER );if (options->persist_mode && options->lladdr) {set_lladdr (ctx, options->dev, options->lladdr,NULL );
@@ -1689,13 +1689,14 @@const struct tuntap *tt, const struct plugin_list *plugins, struct env_set *es, - openvpn_net_ctx_t *ctx) + openvpn_net_ctx_t *ctx, + const bool is_multipoint) { bool ret = true;if (!options->route_noexec && ( route_list || route_ipv6_list ) ) { ret =add_routes (route_list, route_ipv6_list, tt,ROUTE_OPTION_FLAGS (options), - es, ctx); + es, ctx, is_multipoint);setenv_int (es,"redirect_gateway" ,route_did_redirect_default_gateway (route_list)); }#ifdef ENABLE_MANAGEMENT
@@ -1898,7 +1899,7 @@ c->options.dev_node, &gc);do_ifconfig (c->c1.tuntap, guess, c->c2.frame.tun_mtu, c->c2.es, - &c->net_ctx); + &c->net_ctx, c->mode ==CM_TOP ); }/* possibly add routes */
@@ -1906,7 +1907,7 @@ {/* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */ bool status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }#ifdef TARGET_ANDROID
@@ -1934,7 +1935,7 @@ && ifconfig_order() == IFCONFIG_AFTER_TUN_OPEN) {do_ifconfig (c->c1.tuntap, c->c1.tuntap->actual_name, - c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx); + c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); }/* run the up script */
@@ -1960,7 +1961,7 @@if ((route_order () ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) {int status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }
@@ -2017,7 +2018,7 @@ {undo_ifconfig (c->c1.tuntap, &c->net_ctx); } -close_tun (c->c1.tuntap, &c->net_ctx); +close_tun (c->c1.tuntap, &c->net_ctx, c->mode ==CM_TOP ); c->c1.tuntap =NULL ; } c->c1.tuntap_owned = false;
@@ -2086,7 +2087,7 @@delete_routes (c->c1.route_list, c->c1.route_ipv6_list, c->c1.tuntap,ROUTE_OPTION_FLAGS (&c->options), - c->c2.es, &c->net_ctx); + c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); }/* actually close tun/tap device based on --down-pre flag */
src/openvpn/init.h +1 -1
@@ -74,7 +74,7 @@bool do_route (const struct options *options,struct route_list *route_list,struct route_ipv6_list *route_ipv6_list,const struct tuntap *tt,const struct plugin_list *plugins,struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint);void close_instance (struct context *c);
src/openvpn/route.c +347 -202
945 lines not on this page · raw message
src/openvpn/route.h +7 -5
@@ -271,13 +271,13 @@void route_ipv6_clear_host_bits (struct route_ipv6 *r6 ); -bool add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx); +bool add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint); -void delete_route_ipv6 (const struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx); +void delete_route_ipv6 (const struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint);bool add_route (struct route_ipv4 *r,const struct tuntap *tt,unsigned int flags,const struct route_gateway_info *rgi,const struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint); void add_route_to_option_list(struct route_option_list *l, const char *network,
@@ -312,14 +312,16 @@bool add_routes (struct route_list *rl,struct route_ipv6_list *rl6,const struct tuntap *tt,unsigned int flags, -const struct env_set *es,openvpn_net_ctx_t *ctx); +const struct env_set *es,openvpn_net_ctx_t *ctx, +const bool is_multipoint);void delete_routes (struct route_list *rl,struct route_ipv6_list *rl6,const struct tuntap *tt,unsigned int flags,const struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx, +const bool is_multipoint);void setenv_routes (struct env_set *es,const struct route_list *rl);
src/openvpn/tun.c +50 -35
338 lines not on this page · raw message
src/openvpn/tun.h +4 -3
@@ -266,7 +266,7 @@void open_tun (const char *dev,const char *dev_type,const char *dev_node,struct tuntap *tt,openvpn_net_ctx_t *ctx); -void close_tun (struct tuntap *tt,openvpn_net_ctx_t *ctx); +void close_tun (struct tuntap *tt,openvpn_net_ctx_t *ctx,const bool is_multipoint);void tun_open_device (struct tuntap *tt,const char *dev_node,const char **device_guid,struct gc_arena *gc);
@@ -280,7 +280,7 @@void tuncfg (const char *dev,const char *dev_type,const char *dev_node,int persist_mode,const char *username,const char *groupname,const struct tuntap_options *options, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint); const char *guess_tuntap_dev(const char *dev, const char *dev_type,
@@ -319,7 +319,7 @@* @param ctx the networking API opaque context */ void do_ifconfig (struct tuntap *tt,const char *ifname,int tun_mtu, -const struct env_set *es,openvpn_net_ctx_t *ctx); +const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint);/** * undo_ifconfig - undo configuration of the tunnel interface
@@ -754,6 +754,7 @@ }const char *tun_stat (const struct tuntap *tt,unsigned int rwflags,struct gc_arena *gc); +bool tun_name_is_fixed (const char *dev); static inline bool
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I87777e74b1fd34781e1d72c9f994eb84f39d800c
Gerrit-Change-Number: 721
Gerrit-PatchSet: 1
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange
Attention is currently required from: flichtenheld, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
to look at the new patch set (#4).
Change subject: route: extended logic to omit gateway when unnecessary
......................................................................
route: extended logic to omit gateway when unnecessary
Extracted and extended the logic behind 'gateway_needed' both in add_route() and add_route_ipv6(). Other than checking the dev-type, special routes and if the gateway is on-link,
- set gateway_needed to true if the vpn instance is a multipoint server and DCO is enabled.
- set gateway_needed to false if the gateway is in the vpn subnet. Additionally, extended support for these checks and conditions to DARWIN and BSD-based operating systems.
These changes ensure that the gateway is only included when necessary, optimizing route configuration and potentially reducing redundant route entries.
---
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/route.c
M src/openvpn/route.h
M src/openvpn/tun.c
M src/openvpn/tun.h
7 files changed, 420 insertions(+), 256 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/21/721/4
src/openvpn/forward.c +1 -1
@@ -421,7 +421,7 @@ check_add_routes_action(struct context *c, const bool errors) { bool route_status = do_route(&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP );int flags = (errors ?ISC_ERRORS :0 ); flags |= (!route_status ?ISC_ROUTE_ERRORS :0 );
src/openvpn/init.c +10 -9
@@ -1134,7 +1134,7 @@tuncfg (options->dev, options->dev_type, options->dev_node, options->persist_mode, options->username, options->groupname, &options->tuntap_options, - ctx); + ctx, options->mode ==MODE_SERVER );if (options->persist_mode && options->lladdr) {set_lladdr (ctx, options->dev, options->lladdr,NULL );
@@ -1689,13 +1689,14 @@const struct tuntap *tt, const struct plugin_list *plugins, struct env_set *es, - openvpn_net_ctx_t *ctx) + openvpn_net_ctx_t *ctx, + const bool is_multipoint) { bool ret = true;if (!options->route_noexec && ( route_list || route_ipv6_list ) ) { ret =add_routes (route_list, route_ipv6_list, tt,ROUTE_OPTION_FLAGS (options), - es, ctx); + es, ctx, is_multipoint);setenv_int (es,"redirect_gateway" ,route_did_redirect_default_gateway (route_list)); }#ifdef ENABLE_MANAGEMENT
@@ -1898,7 +1899,7 @@ c->options.dev_node, &gc);do_ifconfig (c->c1.tuntap, guess, c->c2.frame.tun_mtu, c->c2.es, - &c->net_ctx); + &c->net_ctx, c->mode ==CM_TOP ); }/* possibly add routes */
@@ -1906,7 +1907,7 @@ {/* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */ bool status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }#ifdef TARGET_ANDROID
@@ -1934,7 +1935,7 @@ && ifconfig_order() == IFCONFIG_AFTER_TUN_OPEN) {do_ifconfig (c->c1.tuntap, c->c1.tuntap->actual_name, - c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx); + c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); }/* run the up script */
@@ -1960,7 +1961,7 @@if ((route_order () ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) {int status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }
@@ -2017,7 +2018,7 @@ {undo_ifconfig (c->c1.tuntap, &c->net_ctx); } -close_tun (c->c1.tuntap, &c->net_ctx); +close_tun (c->c1.tuntap, &c->net_ctx, c->mode ==CM_TOP ); c->c1.tuntap =NULL ; } c->c1.tuntap_owned = false;
@@ -2086,7 +2087,7 @@delete_routes (c->c1.route_list, c->c1.route_ipv6_list, c->c1.tuntap,ROUTE_OPTION_FLAGS (&c->options), - c->c2.es, &c->net_ctx); + c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); }/* actually close tun/tap device based on --down-pre flag */
src/openvpn/init.h +1 -1
@@ -74,7 +74,7 @@bool do_route (const struct options *options,struct route_list *route_list,struct route_ipv6_list *route_ipv6_list,const struct tuntap *tt,const struct plugin_list *plugins,struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint);void close_instance (struct context *c);
src/openvpn/route.c +347 -202
945 lines not on this page · raw message
src/openvpn/route.h +7 -5
@@ -271,13 +271,13 @@void route_ipv6_clear_host_bits (struct route_ipv6 *r6 ); -bool add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx); +bool add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint); -void delete_route_ipv6 (const struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx); +void delete_route_ipv6 (const struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint);bool add_route (struct route_ipv4 *r,const struct tuntap *tt,unsigned int flags,const struct route_gateway_info *rgi,const struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint); void add_route_to_option_list(struct route_option_list *l, const char *network,
@@ -312,14 +312,16 @@bool add_routes (struct route_list *rl,struct route_ipv6_list *rl6,const struct tuntap *tt,unsigned int flags, -const struct env_set *es,openvpn_net_ctx_t *ctx); +const struct env_set *es,openvpn_net_ctx_t *ctx, +const bool is_multipoint);void delete_routes (struct route_list *rl,struct route_ipv6_list *rl6,const struct tuntap *tt,unsigned int flags,const struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx, +const bool is_multipoint);void setenv_routes (struct env_set *es,const struct route_list *rl);
src/openvpn/tun.c +50 -35
338 lines not on this page · raw message
src/openvpn/tun.h +4 -3
@@ -266,7 +266,7 @@void open_tun (const char *dev,const char *dev_type,const char *dev_node,struct tuntap *tt,openvpn_net_ctx_t *ctx); -void close_tun (struct tuntap *tt,openvpn_net_ctx_t *ctx); +void close_tun (struct tuntap *tt,openvpn_net_ctx_t *ctx,const bool is_multipoint);void tun_open_device (struct tuntap *tt,const char *dev_node,const char **device_guid,struct gc_arena *gc);
@@ -280,7 +280,7 @@void tuncfg (const char *dev,const char *dev_type,const char *dev_node,int persist_mode,const char *username,const char *groupname,const struct tuntap_options *options, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint); const char *guess_tuntap_dev(const char *dev, const char *dev_type,
@@ -319,7 +319,7 @@* @param ctx the networking API opaque context */ void do_ifconfig (struct tuntap *tt,const char *ifname,int tun_mtu, -const struct env_set *es,openvpn_net_ctx_t *ctx); +const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint);/** * undo_ifconfig - undo configuration of the tunnel interface
@@ -754,6 +754,7 @@ }const char *tun_stat (const struct tuntap *tt,unsigned int rwflags,struct gc_arena *gc); +bool tun_name_is_fixed (const char *dev); static inline bool
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I87777e74b1fd34781e1d72c9f994eb84f39d800c
Gerrit-Change-Number: 721
Gerrit-PatchSet: 4
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
to look at the new patch set (#5).
Change subject: route: extended logic to omit gateway when unnecessary
......................................................................
route: extended logic to omit gateway when unnecessary
Extracted and extended the logic behind 'gateway_needed' both in add_route() and add_route_ipv6(). Other than checking the dev-type, special routes and if the gateway is on-link,
- set gateway_needed to true if the vpn instance is a multipoint server and DCO is enabled.
- set gateway_needed to false if the gateway is in the vpn subnet. Additionally, extended support for these checks and conditions to DARWIN and BSD-based operating systems.
These changes ensure that the gateway is only included when necessary, optimizing route configuration and potentially reducing redundant route entries.
---
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/route.c
M src/openvpn/route.h
M src/openvpn/tun.c
M src/openvpn/tun.h
7 files changed, 417 insertions(+), 256 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/21/721/5
src/openvpn/forward.c +1 -1
@@ -421,7 +421,7 @@ check_add_routes_action(struct context *c, const bool errors) { bool route_status = do_route(&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP );int flags = (errors ?ISC_ERRORS :0 ); flags |= (!route_status ?ISC_ROUTE_ERRORS :0 );
src/openvpn/init.c +10 -9
@@ -1134,7 +1134,7 @@tuncfg (options->dev, options->dev_type, options->dev_node, options->persist_mode, options->username, options->groupname, &options->tuntap_options, - ctx); + ctx, options->mode ==MODE_SERVER );if (options->persist_mode && options->lladdr) {set_lladdr (ctx, options->dev, options->lladdr,NULL );
@@ -1689,13 +1689,14 @@const struct tuntap *tt, const struct plugin_list *plugins, struct env_set *es, - openvpn_net_ctx_t *ctx) + openvpn_net_ctx_t *ctx, + const bool is_multipoint) { bool ret = true;if (!options->route_noexec && ( route_list || route_ipv6_list ) ) { ret =add_routes (route_list, route_ipv6_list, tt,ROUTE_OPTION_FLAGS (options), - es, ctx); + es, ctx, is_multipoint);setenv_int (es,"redirect_gateway" ,route_did_redirect_default_gateway (route_list)); }#ifdef ENABLE_MANAGEMENT
@@ -1898,7 +1899,7 @@ c->options.dev_node, &gc);do_ifconfig (c->c1.tuntap, guess, c->c2.frame.tun_mtu, c->c2.es, - &c->net_ctx); + &c->net_ctx, c->mode ==CM_TOP ); }/* possibly add routes */
@@ -1906,7 +1907,7 @@ {/* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */ bool status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }#ifdef TARGET_ANDROID
@@ -1934,7 +1935,7 @@ && ifconfig_order() == IFCONFIG_AFTER_TUN_OPEN) {do_ifconfig (c->c1.tuntap, c->c1.tuntap->actual_name, - c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx); + c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); }/* run the up script */
@@ -1960,7 +1961,7 @@if ((route_order () ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) {int status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }
@@ -2017,7 +2018,7 @@ {undo_ifconfig (c->c1.tuntap, &c->net_ctx); } -close_tun (c->c1.tuntap, &c->net_ctx); +close_tun (c->c1.tuntap, &c->net_ctx, c->mode ==CM_TOP ); c->c1.tuntap =NULL ; } c->c1.tuntap_owned = false;
@@ -2086,7 +2087,7 @@delete_routes (c->c1.route_list, c->c1.route_ipv6_list, c->c1.tuntap,ROUTE_OPTION_FLAGS (&c->options), - c->c2.es, &c->net_ctx); + c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); }/* actually close tun/tap device based on --down-pre flag */
src/openvpn/init.h +1 -1
@@ -74,7 +74,7 @@bool do_route (const struct options *options,struct route_list *route_list,struct route_ipv6_list *route_ipv6_list,const struct tuntap *tt,const struct plugin_list *plugins,struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint);void close_instance (struct context *c);
src/openvpn/route.c +344 -202
942 lines not on this page · raw message
src/openvpn/route.h +7 -5
@@ -271,13 +271,13 @@void route_ipv6_clear_host_bits (struct route_ipv6 *r6 ); -bool add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx); +bool add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint); -void delete_route_ipv6 (const struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx); +void delete_route_ipv6 (const struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint);bool add_route (struct route_ipv4 *r,const struct tuntap *tt,unsigned int flags,const struct route_gateway_info *rgi,const struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint); void add_route_to_option_list(struct route_option_list *l, const char *network,
@@ -312,14 +312,16 @@bool add_routes (struct route_list *rl,struct route_ipv6_list *rl6,const struct tuntap *tt,unsigned int flags, -const struct env_set *es,openvpn_net_ctx_t *ctx); +const struct env_set *es,openvpn_net_ctx_t *ctx, +const bool is_multipoint);void delete_routes (struct route_list *rl,struct route_ipv6_list *rl6,const struct tuntap *tt,unsigned int flags,const struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx, +const bool is_multipoint);void setenv_routes (struct env_set *es,const struct route_list *rl);
src/openvpn/tun.c +50 -35
338 lines not on this page · raw message
src/openvpn/tun.h +4 -3
@@ -266,7 +266,7 @@void open_tun (const char *dev,const char *dev_type,const char *dev_node,struct tuntap *tt,openvpn_net_ctx_t *ctx); -void close_tun (struct tuntap *tt,openvpn_net_ctx_t *ctx); +void close_tun (struct tuntap *tt,openvpn_net_ctx_t *ctx,const bool is_multipoint);void tun_open_device (struct tuntap *tt,const char *dev_node,const char **device_guid,struct gc_arena *gc);
@@ -280,7 +280,7 @@void tuncfg (const char *dev,const char *dev_type,const char *dev_node,int persist_mode,const char *username,const char *groupname,const struct tuntap_options *options, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint); const char *guess_tuntap_dev(const char *dev, const char *dev_type,
@@ -319,7 +319,7 @@* @param ctx the networking API opaque context */ void do_ifconfig (struct tuntap *tt,const char *ifname,int tun_mtu, -const struct env_set *es,openvpn_net_ctx_t *ctx); +const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint);/** * undo_ifconfig - undo configuration of the tunnel interface
@@ -754,6 +754,7 @@ }const char *tun_stat (const struct tuntap *tt,unsigned int rwflags,struct gc_arena *gc); +bool tun_name_is_fixed (const char *dev); static inline bool
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I87777e74b1fd34781e1d72c9f994eb84f39d800c
Gerrit-Change-Number: 721
Gerrit-PatchSet: 5
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
to look at the new patch set (#6).
Change subject: route: extended logic to omit gateway when unnecessary
......................................................................
route: extended logic to omit gateway when unnecessary
Extracted and extended the logic behind 'gateway_needed' both in add_route() and add_route_ipv6(). Other than checking the dev-type, special routes and if the gateway is on-link,
- set gateway_needed to true if the vpn instance is a multipoint server and DCO is enabled.
- set gateway_needed to false if the gateway is in the vpn subnet. Additionally, extended support for these checks and conditions to DARWIN and BSD-based operating systems.
These changes ensure that the gateway is only included when necessary, optimizing route configuration and potentially reducing redundant route entries.
---
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/route.c
M src/openvpn/route.h
M src/openvpn/tun.c
M src/openvpn/tun.h
7 files changed, 416 insertions(+), 255 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/21/721/6
src/openvpn/forward.c +1 -1
@@ -421,7 +421,7 @@ check_add_routes_action(struct context *c, const bool errors) { bool route_status = do_route(&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP );int flags = (errors ?ISC_ERRORS :0 ); flags |= (!route_status ?ISC_ROUTE_ERRORS :0 );
src/openvpn/init.c +10 -9
@@ -1134,7 +1134,7 @@tuncfg (options->dev, options->dev_type, options->dev_node, options->persist_mode, options->username, options->groupname, &options->tuntap_options, - ctx); + ctx, options->mode ==MODE_SERVER );if (options->persist_mode && options->lladdr) {set_lladdr (ctx, options->dev, options->lladdr,NULL );
@@ -1689,13 +1689,14 @@const struct tuntap *tt, const struct plugin_list *plugins, struct env_set *es, - openvpn_net_ctx_t *ctx) + openvpn_net_ctx_t *ctx, + const bool is_multipoint) { bool ret = true;if (!options->route_noexec && ( route_list || route_ipv6_list ) ) { ret =add_routes (route_list, route_ipv6_list, tt,ROUTE_OPTION_FLAGS (options), - es, ctx); + es, ctx, is_multipoint);setenv_int (es,"redirect_gateway" ,route_did_redirect_default_gateway (route_list)); }#ifdef ENABLE_MANAGEMENT
@@ -1898,7 +1899,7 @@ c->options.dev_node, &gc);do_ifconfig (c->c1.tuntap, guess, c->c2.frame.tun_mtu, c->c2.es, - &c->net_ctx); + &c->net_ctx, c->mode ==CM_TOP ); }/* possibly add routes */
@@ -1906,7 +1907,7 @@ {/* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */ bool status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }#ifdef TARGET_ANDROID
@@ -1934,7 +1935,7 @@ && ifconfig_order() == IFCONFIG_AFTER_TUN_OPEN) {do_ifconfig (c->c1.tuntap, c->c1.tuntap->actual_name, - c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx); + c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); }/* run the up script */
@@ -1960,7 +1961,7 @@if ((route_order () ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) {int status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }
@@ -2017,7 +2018,7 @@ {undo_ifconfig (c->c1.tuntap, &c->net_ctx); } -close_tun (c->c1.tuntap, &c->net_ctx); +close_tun (c->c1.tuntap, &c->net_ctx, c->mode ==CM_TOP ); c->c1.tuntap =NULL ; } c->c1.tuntap_owned = false;
@@ -2086,7 +2087,7 @@delete_routes (c->c1.route_list, c->c1.route_ipv6_list, c->c1.tuntap,ROUTE_OPTION_FLAGS (&c->options), - c->c2.es, &c->net_ctx); + c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); }/* actually close tun/tap device based on --down-pre flag */
src/openvpn/init.h +1 -1
@@ -74,7 +74,7 @@bool do_route (const struct options *options,struct route_list *route_list,struct route_ipv6_list *route_ipv6_list,const struct tuntap *tt,const struct plugin_list *plugins,struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint);void close_instance (struct context *c);
src/openvpn/route.c +344 -202
942 lines not on this page · raw message
src/openvpn/route.h +7 -5
@@ -271,13 +271,13 @@void route_ipv6_clear_host_bits (struct route_ipv6 *r6 ); -bool add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx); +bool add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint); -void delete_route_ipv6 (const struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx); +void delete_route_ipv6 (const struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint);bool add_route (struct route_ipv4 *r,const struct tuntap *tt,unsigned int flags,const struct route_gateway_info *rgi,const struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint); void add_route_to_option_list(struct route_option_list *l, const char *network,
@@ -312,14 +312,16 @@bool add_routes (struct route_list *rl,struct route_ipv6_list *rl6,const struct tuntap *tt,unsigned int flags, -const struct env_set *es,openvpn_net_ctx_t *ctx); +const struct env_set *es,openvpn_net_ctx_t *ctx, +const bool is_multipoint);void delete_routes (struct route_list *rl,struct route_ipv6_list *rl6,const struct tuntap *tt,unsigned int flags,const struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx, +const bool is_multipoint);void setenv_routes (struct env_set *es,const struct route_list *rl);
src/openvpn/tun.c +49 -34
330 lines not on this page · raw message
src/openvpn/tun.h +4 -3
@@ -266,7 +266,7 @@void open_tun (const char *dev,const char *dev_type,const char *dev_node,struct tuntap *tt,openvpn_net_ctx_t *ctx); -void close_tun (struct tuntap *tt,openvpn_net_ctx_t *ctx); +void close_tun (struct tuntap *tt,openvpn_net_ctx_t *ctx,const bool is_multipoint);void tun_open_device (struct tuntap *tt,const char *dev_node,const char **device_guid,struct gc_arena *gc);
@@ -280,7 +280,7 @@void tuncfg (const char *dev,const char *dev_type,const char *dev_node,int persist_mode,const char *username,const char *groupname,const struct tuntap_options *options, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint); const char *guess_tuntap_dev(const char *dev, const char *dev_type,
@@ -319,7 +319,7 @@* @param ctx the networking API opaque context */ void do_ifconfig (struct tuntap *tt,const char *ifname,int tun_mtu, -const struct env_set *es,openvpn_net_ctx_t *ctx); +const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint);/** * undo_ifconfig - undo configuration of the tunnel interface
@@ -754,6 +754,7 @@ }const char *tun_stat (const struct tuntap *tt,unsigned int rwflags,struct gc_arena *gc); +bool tun_name_is_fixed (const char *dev); static inline bool
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I87777e74b1fd34781e1d72c9f994eb84f39d800c
Gerrit-Change-Number: 721
Gerrit-PatchSet: 6
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
to look at the new patch set (#8).
Change subject: route: extended logic to omit gateway when unnecessary
......................................................................
route: extended logic to omit gateway when unnecessary
Extracted and extended the logic behind 'gateway_needed' both in add_route() and add_route_ipv6(). Other than checking the dev-type, special routes and if the gateway is on-link,
- set gateway_needed to true if the vpn instance is a multipoint server and DCO is enabled.
- set gateway_needed to false if the gateway is in the vpn subnet. Additionally, extended support for these checks and conditions to DARWIN and BSD-based operating systems.
These changes ensure that the gateway is only included when necessary, optimizing route configuration and potentially reducing redundant route entries.
---
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/route.c
M src/openvpn/route.h
M src/openvpn/tun.c
M src/openvpn/tun.h
7 files changed, 416 insertions(+), 253 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/21/721/8
src/openvpn/forward.c +1 -1
@@ -421,7 +421,7 @@ check_add_routes_action(struct context *c, const bool errors) { bool route_status = do_route(&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP );int flags = (errors ?ISC_ERRORS :0 ); flags |= (!route_status ?ISC_ROUTE_ERRORS :0 );
src/openvpn/init.c +10 -9
@@ -1134,7 +1134,7 @@tuncfg (options->dev, options->dev_type, options->dev_node, options->persist_mode, options->username, options->groupname, &options->tuntap_options, - ctx); + ctx, options->mode ==MODE_SERVER );if (options->persist_mode && options->lladdr) {set_lladdr (ctx, options->dev, options->lladdr,NULL );
@@ -1689,13 +1689,14 @@const struct tuntap *tt, const struct plugin_list *plugins, struct env_set *es, - openvpn_net_ctx_t *ctx) + openvpn_net_ctx_t *ctx, + const bool is_multipoint) { bool ret = true;if (!options->route_noexec && ( route_list || route_ipv6_list ) ) { ret =add_routes (route_list, route_ipv6_list, tt,ROUTE_OPTION_FLAGS (options), - es, ctx); + es, ctx, is_multipoint);setenv_int (es,"redirect_gateway" ,route_did_redirect_default_gateway (route_list)); }#ifdef ENABLE_MANAGEMENT
@@ -1898,7 +1899,7 @@ c->options.dev_node, &gc);do_ifconfig (c->c1.tuntap, guess, c->c2.frame.tun_mtu, c->c2.es, - &c->net_ctx); + &c->net_ctx, c->mode ==CM_TOP ); }/* possibly add routes */
@@ -1906,7 +1907,7 @@ {/* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */ bool status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }#ifdef TARGET_ANDROID
@@ -1934,7 +1935,7 @@ && ifconfig_order() == IFCONFIG_AFTER_TUN_OPEN) {do_ifconfig (c->c1.tuntap, c->c1.tuntap->actual_name, - c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx); + c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); }/* run the up script */
@@ -1960,7 +1961,7 @@if ((route_order () ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) {int status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }
@@ -2017,7 +2018,7 @@ {undo_ifconfig (c->c1.tuntap, &c->net_ctx); } -close_tun (c->c1.tuntap, &c->net_ctx); +close_tun (c->c1.tuntap, &c->net_ctx, c->mode ==CM_TOP ); c->c1.tuntap =NULL ; } c->c1.tuntap_owned = false;
@@ -2086,7 +2087,7 @@delete_routes (c->c1.route_list, c->c1.route_ipv6_list, c->c1.tuntap,ROUTE_OPTION_FLAGS (&c->options), - c->c2.es, &c->net_ctx); + c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); }/* actually close tun/tap device based on --down-pre flag */
src/openvpn/init.h +1 -1
@@ -74,7 +74,7 @@bool do_route (const struct options *options,struct route_list *route_list,struct route_ipv6_list *route_ipv6_list,const struct tuntap *tt,const struct plugin_list *plugins,struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint);void close_instance (struct context *c);
src/openvpn/route.c +344 -200
940 lines not on this page · raw message
src/openvpn/route.h +7 -5
@@ -271,13 +271,13 @@void route_ipv6_clear_host_bits (struct route_ipv6 *r6 ); -bool add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx); +bool add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint); -void delete_route_ipv6 (const struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx); +void delete_route_ipv6 (const struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint);bool add_route (struct route_ipv4 *r,const struct tuntap *tt,unsigned int flags,const struct route_gateway_info *rgi,const struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint); void add_route_to_option_list(struct route_option_list *l, const char *network,
@@ -312,14 +312,16 @@bool add_routes (struct route_list *rl,struct route_ipv6_list *rl6,const struct tuntap *tt,unsigned int flags, -const struct env_set *es,openvpn_net_ctx_t *ctx); +const struct env_set *es,openvpn_net_ctx_t *ctx, +const bool is_multipoint);void delete_routes (struct route_list *rl,struct route_ipv6_list *rl6,const struct tuntap *tt,unsigned int flags,const struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx, +const bool is_multipoint);void setenv_routes (struct env_set *es,const struct route_list *rl);
src/openvpn/tun.c +49 -34
330 lines not on this page · raw message
src/openvpn/tun.h +4 -3
@@ -266,7 +266,7 @@void open_tun (const char *dev,const char *dev_type,const char *dev_node,struct tuntap *tt,openvpn_net_ctx_t *ctx); -void close_tun (struct tuntap *tt,openvpn_net_ctx_t *ctx); +void close_tun (struct tuntap *tt,openvpn_net_ctx_t *ctx,const bool is_multipoint);void tun_open_device (struct tuntap *tt,const char *dev_node,const char **device_guid,struct gc_arena *gc);
@@ -280,7 +280,7 @@void tuncfg (const char *dev,const char *dev_type,const char *dev_node,int persist_mode,const char *username,const char *groupname,const struct tuntap_options *options, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint); const char *guess_tuntap_dev(const char *dev, const char *dev_type,
@@ -319,7 +319,7 @@* @param ctx the networking API opaque context */ void do_ifconfig (struct tuntap *tt,const char *ifname,int tun_mtu, -const struct env_set *es,openvpn_net_ctx_t *ctx); +const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint);/** * undo_ifconfig - undo configuration of the tunnel interface
@@ -754,6 +754,7 @@ }const char *tun_stat (const struct tuntap *tt,unsigned int rwflags,struct gc_arena *gc); +bool tun_name_is_fixed (const char *dev); static inline bool
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I87777e74b1fd34781e1d72c9f994eb84f39d800c
Gerrit-Change-Number: 721
Gerrit-PatchSet: 8
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
to look at the new patch set (#9).
Change subject: route: extended logic to omit gateway when unnecessary
......................................................................
route: extended logic to omit gateway when unnecessary
Extracted and extended the logic behind 'gateway_needed' both in add_route() and add_route_ipv6(). Other than checking the dev-type, special routes and if the gateway is on-link,
- set gateway_needed to true if the vpn instance is a multipoint server and DCO is enabled.
- set gateway_needed to false if the gateway is in the vpn subnet. Additionally, extended support for these checks and conditions to DARWIN and BSD-based operating systems.
These changes ensure that the gateway is only included when necessary, optimizing route configuration and potentially reducing redundant route entries.
---
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/route.c
M src/openvpn/route.h
M src/openvpn/tun.c
M src/openvpn/tun.h
7 files changed, 418 insertions(+), 253 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/21/721/9
src/openvpn/forward.c +1 -1
@@ -421,7 +421,7 @@ check_add_routes_action(struct context *c, const bool errors) { bool route_status = do_route(&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP );int flags = (errors ?ISC_ERRORS :0 ); flags |= (!route_status ?ISC_ROUTE_ERRORS :0 );
src/openvpn/init.c +10 -9
@@ -1134,7 +1134,7 @@tuncfg (options->dev, options->dev_type, options->dev_node, options->persist_mode, options->username, options->groupname, &options->tuntap_options, - ctx); + ctx, options->mode ==MODE_SERVER );if (options->persist_mode && options->lladdr) {set_lladdr (ctx, options->dev, options->lladdr,NULL );
@@ -1689,13 +1689,14 @@const struct tuntap *tt, const struct plugin_list *plugins, struct env_set *es, - openvpn_net_ctx_t *ctx) + openvpn_net_ctx_t *ctx, + const bool is_multipoint) { bool ret = true;if (!options->route_noexec && ( route_list || route_ipv6_list ) ) { ret =add_routes (route_list, route_ipv6_list, tt,ROUTE_OPTION_FLAGS (options), - es, ctx); + es, ctx, is_multipoint);setenv_int (es,"redirect_gateway" ,route_did_redirect_default_gateway (route_list)); }#ifdef ENABLE_MANAGEMENT
@@ -1898,7 +1899,7 @@ c->options.dev_node, &gc);do_ifconfig (c->c1.tuntap, guess, c->c2.frame.tun_mtu, c->c2.es, - &c->net_ctx); + &c->net_ctx, c->mode ==CM_TOP ); }/* possibly add routes */
@@ -1906,7 +1907,7 @@ {/* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */ bool status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }#ifdef TARGET_ANDROID
@@ -1934,7 +1935,7 @@ && ifconfig_order() == IFCONFIG_AFTER_TUN_OPEN) {do_ifconfig (c->c1.tuntap, c->c1.tuntap->actual_name, - c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx); + c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); }/* run the up script */
@@ -1960,7 +1961,7 @@if ((route_order () ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) {int status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }
@@ -2017,7 +2018,7 @@ {undo_ifconfig (c->c1.tuntap, &c->net_ctx); } -close_tun (c->c1.tuntap, &c->net_ctx); +close_tun (c->c1.tuntap, &c->net_ctx, c->mode ==CM_TOP ); c->c1.tuntap =NULL ; } c->c1.tuntap_owned = false;
@@ -2086,7 +2087,7 @@delete_routes (c->c1.route_list, c->c1.route_ipv6_list, c->c1.tuntap,ROUTE_OPTION_FLAGS (&c->options), - c->c2.es, &c->net_ctx); + c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); }/* actually close tun/tap device based on --down-pre flag */
src/openvpn/init.h +1 -1
@@ -74,7 +74,7 @@bool do_route (const struct options *options,struct route_list *route_list,struct route_ipv6_list *route_ipv6_list,const struct tuntap *tt,const struct plugin_list *plugins,struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint);void close_instance (struct context *c);
src/openvpn/route.c +346 -200
942 lines not on this page · raw message
src/openvpn/route.h +7 -5
@@ -271,13 +271,13 @@void route_ipv6_clear_host_bits (struct route_ipv6 *r6 ); -bool add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx); +bool add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint); -void delete_route_ipv6 (const struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx); +void delete_route_ipv6 (const struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint);bool add_route (struct route_ipv4 *r,const struct tuntap *tt,unsigned int flags,const struct route_gateway_info *rgi,const struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint); void add_route_to_option_list(struct route_option_list *l, const char *network,
@@ -312,14 +312,16 @@bool add_routes (struct route_list *rl,struct route_ipv6_list *rl6,const struct tuntap *tt,unsigned int flags, -const struct env_set *es,openvpn_net_ctx_t *ctx); +const struct env_set *es,openvpn_net_ctx_t *ctx, +const bool is_multipoint);void delete_routes (struct route_list *rl,struct route_ipv6_list *rl6,const struct tuntap *tt,unsigned int flags,const struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx, +const bool is_multipoint);void setenv_routes (struct env_set *es,const struct route_list *rl);
src/openvpn/tun.c +49 -34
330 lines not on this page · raw message
src/openvpn/tun.h +4 -3
@@ -266,7 +266,7 @@void open_tun (const char *dev,const char *dev_type,const char *dev_node,struct tuntap *tt,openvpn_net_ctx_t *ctx); -void close_tun (struct tuntap *tt,openvpn_net_ctx_t *ctx); +void close_tun (struct tuntap *tt,openvpn_net_ctx_t *ctx,const bool is_multipoint);void tun_open_device (struct tuntap *tt,const char *dev_node,const char **device_guid,struct gc_arena *gc);
@@ -280,7 +280,7 @@void tuncfg (const char *dev,const char *dev_type,const char *dev_node,int persist_mode,const char *username,const char *groupname,const struct tuntap_options *options, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint); const char *guess_tuntap_dev(const char *dev, const char *dev_type,
@@ -319,7 +319,7 @@* @param ctx the networking API opaque context */ void do_ifconfig (struct tuntap *tt,const char *ifname,int tun_mtu, -const struct env_set *es,openvpn_net_ctx_t *ctx); +const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint);/** * undo_ifconfig - undo configuration of the tunnel interface
@@ -754,6 +754,7 @@ }const char *tun_stat (const struct tuntap *tt,unsigned int rwflags,struct gc_arena *gc); +bool tun_name_is_fixed (const char *dev); static inline bool
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I87777e74b1fd34781e1d72c9f994eb84f39d800c
Gerrit-Change-Number: 721
Gerrit-PatchSet: 9
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
to look at the new patch set (#10).
Change subject: route: extended logic to omit gateway when unnecessary
......................................................................
route: extended logic to omit gateway when unnecessary
Extracted and extended the logic behind 'gateway_needed' both in add_route() and add_route_ipv6(). Other than checking the dev-type, special routes and if the gateway is on-link,
- set gateway_needed to true if the vpn instance is a multipoint server and DCO is enabled.
- set gateway_needed to false if the gateway is in the vpn subnet. Additionally, extended support for these checks and conditions to DARWIN and BSD-based operating systems.
These changes ensure that the gateway is only included when necessary, optimizing route configuration and potentially reducing redundant route entries.
---
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/route.c
M src/openvpn/route.h
M src/openvpn/tun.c
M src/openvpn/tun.h
7 files changed, 417 insertions(+), 252 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/21/721/10
src/openvpn/forward.c +1 -1
@@ -427,7 +427,7 @@ check_add_routes_action(struct context *c, const bool errors) { bool route_status = do_route(&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP );int flags = (errors ?ISC_ERRORS :0 ); flags |= (!route_status ?ISC_ROUTE_ERRORS :0 );
src/openvpn/init.c +9 -8
@@ -1152,7 +1152,7 @@tuncfg (options->dev, options->dev_type, options->dev_node, options->persist_mode, options->username, options->groupname, &options->tuntap_options, - ctx); + ctx, options->mode ==MODE_SERVER );if (options->persist_mode && options->lladdr) {set_lladdr (ctx, options->dev, options->lladdr,NULL );
@@ -1719,13 +1719,14 @@const struct tuntap *tt, const struct plugin_list *plugins, struct env_set *es, - openvpn_net_ctx_t *ctx) + openvpn_net_ctx_t *ctx, + const bool is_multipoint) { bool ret = true;if (!route_noexec_enabled (options, tt) && ( route_list || route_ipv6_list ) ) { ret =add_routes (route_list, route_ipv6_list, tt,ROUTE_OPTION_FLAGS (options), - es, ctx); + es, ctx, is_multipoint);setenv_int (es,"redirect_gateway" ,route_did_redirect_default_gateway (route_list)); }#ifdef ENABLE_MANAGEMENT
@@ -1987,7 +1988,7 @@ c->options.dev_type, c->options.dev_node, &gc); -do_ifconfig (c->c1.tuntap, guess, c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx); +do_ifconfig (c->c1.tuntap, guess, c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); }/* possibly add routes */
@@ -1995,7 +1996,7 @@ {/* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */ bool status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }#ifdef TARGET_ANDROID
@@ -2022,7 +2023,7 @@ && ifconfig_order(c->c1.tuntap) == IFCONFIG_AFTER_TUN_OPEN) {do_ifconfig (c->c1.tuntap, c->c1.tuntap->actual_name, - c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx); + c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); }/* run the up script */
@@ -2048,7 +2049,7 @@if ((route_order (c->c1.tuntap) ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) {int status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }
@@ -2186,7 +2187,7 @@delete_routes (c->c1.route_list, c->c1.route_ipv6_list, c->c1.tuntap,ROUTE_OPTION_FLAGS (&c->options), - c->c2.es, &c->net_ctx); + c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); }/* actually close tun/tap device based on --down-pre flag */
src/openvpn/init.h +1 -1
@@ -74,7 +74,7 @@bool do_route (const struct options *options,struct route_list *route_list,struct route_ipv6_list *route_ipv6_list,const struct tuntap *tt,const struct plugin_list *plugins,struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint);void close_instance (struct context *c);
src/openvpn/route.c +346 -200
942 lines not on this page · raw message
src/openvpn/route.h +7 -5
@@ -271,13 +271,13 @@void route_ipv6_clear_host_bits (struct route_ipv6 *r6 ); -bool add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx); +bool add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint); -void delete_route_ipv6 (const struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx); +void delete_route_ipv6 (const struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint);bool add_route (struct route_ipv4 *r,const struct tuntap *tt,unsigned int flags,const struct route_gateway_info *rgi,const struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint); void add_route_to_option_list(struct route_option_list *l, const char *network,
@@ -312,14 +312,16 @@bool add_routes (struct route_list *rl,struct route_ipv6_list *rl6,const struct tuntap *tt,unsigned int flags, -const struct env_set *es,openvpn_net_ctx_t *ctx); +const struct env_set *es,openvpn_net_ctx_t *ctx, +const bool is_multipoint);void delete_routes (struct route_list *rl,struct route_ipv6_list *rl6,const struct tuntap *tt,unsigned int flags,const struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx, +const bool is_multipoint);void setenv_routes (struct env_set *es,const struct route_list *rl);
src/openvpn/tun.c +49 -34
330 lines not on this page · raw message
src/openvpn/tun.h +4 -3
@@ -282,7 +282,7 @@void open_tun (const char *dev,const char *dev_type,const char *dev_node,struct tuntap *tt,openvpn_net_ctx_t *ctx); -void close_tun (struct tuntap *tt,openvpn_net_ctx_t *ctx); +void close_tun (struct tuntap *tt,openvpn_net_ctx_t *ctx,const bool is_multipoint);void tun_open_device (struct tuntap *tt,const char *dev_node,const char **device_guid,struct gc_arena *gc);
@@ -296,7 +296,7 @@void tuncfg (const char *dev,const char *dev_type,const char *dev_node,int persist_mode,const char *username,const char *groupname,const struct tuntap_options *options, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint); const char *guess_tuntap_dev(const char *dev, const char *dev_type,
@@ -335,7 +335,7 @@* @param ctx the networking API opaque context */ void do_ifconfig (struct tuntap *tt,const char *ifname,int tun_mtu, -const struct env_set *es,openvpn_net_ctx_t *ctx); +const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint);/** * undo_ifconfig - undo configuration of the tunnel interface
@@ -781,6 +781,7 @@ }const char *tun_stat (const struct tuntap *tt,unsigned int rwflags,struct gc_arena *gc); +bool tun_name_is_fixed (const char *dev); static inline bool
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I87777e74b1fd34781e1d72c9f994eb84f39d800c
Gerrit-Change-Number: 721
Gerrit-PatchSet: 10
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
to look at the new patch set (#11).
Change subject: route: extended logic to omit gateway when unnecessary
......................................................................
route: extended logic to omit gateway when unnecessary
Extracted and extended the logic behind 'gateway_needed' both in add_route() and add_route_ipv6(). Other than checking the dev-type, special routes and if the gateway is on-link,
- set gateway_needed to true if the vpn instance is a multipoint server and DCO is enabled.
- set gateway_needed to false if the gateway is in the vpn subnet. Additionally, extended support for these checks and conditions to DARWIN and BSD-based operating systems.
These changes ensure that the gateway is only included when necessary, optimizing route configuration and potentially reducing redundant route entries.
---
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/route.c
M src/openvpn/route.h
M src/openvpn/tun.c
M src/openvpn/tun.h
7 files changed, 420 insertions(+), 253 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/21/721/11
src/openvpn/forward.c +1 -1
@@ -427,7 +427,7 @@ check_add_routes_action(struct context *c, const bool errors) { bool route_status = do_route(&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP );int flags = (errors ?ISC_ERRORS :0 ); flags |= (!route_status ?ISC_ROUTE_ERRORS :0 );
src/openvpn/init.c +10 -9
@@ -1152,7 +1152,7 @@tuncfg (options->dev, options->dev_type, options->dev_node, options->persist_mode, options->username, options->groupname, &options->tuntap_options, - ctx); + ctx, options->mode ==MODE_SERVER );if (options->persist_mode && options->lladdr) {set_lladdr (ctx, options->dev, options->lladdr,NULL );
@@ -1719,13 +1719,14 @@const struct tuntap *tt, const struct plugin_list *plugins, struct env_set *es, - openvpn_net_ctx_t *ctx) + openvpn_net_ctx_t *ctx, + const bool is_multipoint) { bool ret = true;if (!route_noexec_enabled (options, tt) && ( route_list || route_ipv6_list ) ) { ret =add_routes (route_list, route_ipv6_list, tt,ROUTE_OPTION_FLAGS (options), - es, ctx); + es, ctx, is_multipoint);setenv_int (es,"redirect_gateway" ,route_did_redirect_default_gateway (route_list)); }#ifdef ENABLE_MANAGEMENT
@@ -1987,7 +1988,7 @@ c->options.dev_type, c->options.dev_node, &gc); -do_ifconfig (c->c1.tuntap, guess, c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx); +do_ifconfig (c->c1.tuntap, guess, c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); }/* possibly add routes */
@@ -1995,7 +1996,7 @@ {/* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */ bool status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }#ifdef TARGET_ANDROID
@@ -2022,7 +2023,7 @@ && ifconfig_order(c->c1.tuntap) == IFCONFIG_AFTER_TUN_OPEN) {do_ifconfig (c->c1.tuntap, c->c1.tuntap->actual_name, - c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx); + c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); }/* run the up script */
@@ -2048,7 +2049,7 @@if ((route_order (c->c1.tuntap) ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) {int status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }
@@ -2116,7 +2117,7 @@ }else { -close_tun (c->c1.tuntap, &c->net_ctx); +close_tun (c->c1.tuntap, &c->net_ctx, c->mode ==CM_TOP ); } c->c1.tuntap =NULL ; }
@@ -2186,7 +2187,7 @@delete_routes (c->c1.route_list, c->c1.route_ipv6_list, c->c1.tuntap,ROUTE_OPTION_FLAGS (&c->options), - c->c2.es, &c->net_ctx); + c->c2.es, &c->net_ctx, c->mode ==CM_TOP ); }/* actually close tun/tap device based on --down-pre flag */
src/openvpn/init.h +1 -1
@@ -74,7 +74,7 @@bool do_route (const struct options *options,struct route_list *route_list,struct route_ipv6_list *route_ipv6_list,const struct tuntap *tt,const struct plugin_list *plugins,struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint);void close_instance (struct context *c);
src/openvpn/route.c +348 -200
944 lines not on this page · raw message
src/openvpn/route.h +7 -5
@@ -271,13 +271,13 @@void route_ipv6_clear_host_bits (struct route_ipv6 *r6 ); -bool add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx); +bool add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint); -void delete_route_ipv6 (const struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx); +void delete_route_ipv6 (const struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint);bool add_route (struct route_ipv4 *r,const struct tuntap *tt,unsigned int flags,const struct route_gateway_info *rgi,const struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint); void add_route_to_option_list(struct route_option_list *l, const char *network,
@@ -312,14 +312,16 @@bool add_routes (struct route_list *rl,struct route_ipv6_list *rl6,const struct tuntap *tt,unsigned int flags, -const struct env_set *es,openvpn_net_ctx_t *ctx); +const struct env_set *es,openvpn_net_ctx_t *ctx, +const bool is_multipoint);void delete_routes (struct route_list *rl,struct route_ipv6_list *rl6,const struct tuntap *tt,unsigned int flags,const struct env_set *es, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx, +const bool is_multipoint);void setenv_routes (struct env_set *es,const struct route_list *rl);
src/openvpn/tun.c +49 -34
330 lines not on this page · raw message
src/openvpn/tun.h +4 -3
@@ -282,7 +282,7 @@void open_tun (const char *dev,const char *dev_type,const char *dev_node,struct tuntap *tt,openvpn_net_ctx_t *ctx); -void close_tun (struct tuntap *tt,openvpn_net_ctx_t *ctx); +void close_tun (struct tuntap *tt,openvpn_net_ctx_t *ctx,const bool is_multipoint);void tun_open_device (struct tuntap *tt,const char *dev_node,const char **device_guid,struct gc_arena *gc);
@@ -296,7 +296,7 @@void tuncfg (const char *dev,const char *dev_type,const char *dev_node,int persist_mode,const char *username,const char *groupname,const struct tuntap_options *options, -openvpn_net_ctx_t *ctx); +openvpn_net_ctx_t *ctx,const bool is_multipoint); const char *guess_tuntap_dev(const char *dev, const char *dev_type,
@@ -335,7 +335,7 @@* @param ctx the networking API opaque context */ void do_ifconfig (struct tuntap *tt,const char *ifname,int tun_mtu, -const struct env_set *es,openvpn_net_ctx_t *ctx); +const struct env_set *es,openvpn_net_ctx_t *ctx,const bool is_multipoint);/** * undo_ifconfig - undo configuration of the tunnel interface
@@ -781,6 +781,7 @@ }const char *tun_stat (const struct tuntap *tt,unsigned int rwflags,struct gc_arena *gc); +bool tun_name_is_fixed (const char *dev); static inline bool
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I87777e74b1fd34781e1d72c9f994eb84f39d800c
Gerrit-Change-Number: 721
Gerrit-PatchSet: 11
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, mrbff.
plaisthos has posted comments on this change by mrbff. ( http://gerrit.openvpn.net/c/openvpn/+/721?usp=email )
Change subject: route: extended logic to omit gateway when unnecessary
......................................................................
Patch Set 11: Code-Review-2
(7 comments)
Patchset:
PS11:
I am seriously confused by this PR. The premise of the PR seems that routes that are setup on the startup of OpenVPN (CM_TOP) need to be handled differrent than routes on the startup of a client or routes that are added later, e.g. by CCD files but I do not see a strong reason why these initial routes should be special in that regard.
File src/openvpn/route.h:
http://gerrit.openvpn.net/c/openvpn/+/721/comment/c375c7a6_648618a0?usp=email :
PS11, Line 274: bool add_route_ipv6(struct route_ipv6 *r, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx, const bool is_multipoint);
The naming here and the usage seem to disagree. is_multipoint sounds like the usage in a p2mp server context but the actual usage is that this flag is only used for the CM_TOP instance, which is more the initialisation of p2mp on startup. So this naming is quite confusing here.
Also why adding a flag as bool to the function vs adding it as extra flag in the route structure.
File src/openvpn/route.c:
http://gerrit.openvpn.net/c/openvpn/+/721/comment/d77240b0_a0c41a4e?usp=email :
PS11, Line 1811: /* FIXME -- add on-link support for Dragonfly */
Has this been really tested on DragonFly BSD?
http://gerrit.openvpn.net/c/openvpn/+/721/comment/f8856fdf_5f40d6a4?usp=email :
PS11, Line 1600: && !( (r4->flags & RT_METRIC_DEFINED) && r4->metric == 0 ) )
how does the metric play into needing a gateway or not?
http://gerrit.openvpn.net/c/openvpn/+/721/comment/ac755fc1_a42389d2?usp=email :
PS11, Line 1607: return true;
A little bit of explanation why DCO is different is needed.
http://gerrit.openvpn.net/c/openvpn/+/721/comment/657a25df_8073c041?usp=email :
PS11, Line 1898: }
Has this been tested on Open and NetBSD?
http://gerrit.openvpn.net/c/openvpn/+/721/comment/715e26fa_29fc79e0?usp=email :
PS11, Line 2010: {
I think this duplicates the code that was publicly accessible in https://gerrit.openvpn.net/c/openvpn/+/1191
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I87777e74b1fd34781e1d72c9f994eb84f39d800c
Gerrit-Change-Number: 721
Gerrit-PatchSet: 11
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Comment-Date: Mon, 13 Oct 2025 15:01:15 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Attention is currently required from: flichtenheld, mrbff.
ordex has posted comments on this change by mrbff. ( http://gerrit.openvpn.net/c/openvpn/+/721?usp=email )
Change subject: route: extended logic to omit gateway when unnecessary
......................................................................
Patch Set 11:
(1 comment)
File src/openvpn/route.c:
http://gerrit.openvpn.net/c/openvpn/+/721/comment/fc18e9d4_45882a8c?usp=email :
PS11, Line 1607: return true;
Quoted 1 line
A little bit of explanation why DCO is different is needed.
we've been debating this part. conclusion was that we can remove the check, as this is not what's needed here.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I87777e74b1fd34781e1d72c9f994eb84f39d800c
Gerrit-Change-Number: 721
Gerrit-PatchSet: 11
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Comment-Date: Tue, 14 Oct 2025 13:16:06 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: plaisthos <[email protected]...>
Attention is currently required from: flichtenheld, mrbff.
plaisthos has posted comments on this change by mrbff. ( http://gerrit.openvpn.net/c/openvpn/+/721?usp=email )
Change subject: route: extended logic to omit gateway when unnecessary
......................................................................
Patch Set 11:
(1 comment)
File src/openvpn/route.c:
http://gerrit.openvpn.net/c/openvpn/+/721/comment/378a6658_7f7cade8?usp=email :
PS11, Line 1607: return true;
Quoted 1 line
we've been debating this part. […]
There should at least be some idea/comment in the source code as well. Otherwise it is just a "magical constant".
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I87777e74b1fd34781e1d72c9f994eb84f39d800c
Gerrit-Change-Number: 721
Gerrit-PatchSet: 11
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Comment-Date: Tue, 14 Oct 2025 13:54:46 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: plaisthos <[email protected]...>
Comment-In-Reply-To: ordex <[email protected]...>
Attention is currently required from: flichtenheld, mrbff.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
to look at the new patch set (#12).
Change subject: route: extended logic to omit gateway when unnecessary
......................................................................
route: extended logic to omit gateway when unnecessary
Extracted and extended the logic behind gateway_needed both in add_route() and add_route_ipv6(). Checking dev-type, special routes, if the gateway is on-link and if the gateway is in the vpn subnet. Additionally, extended support for these checks and conditions to DARWIN and BSD-based operating systems.
These changes ensure that the gateway is only included when necessary, optimizing route configuration and potentially reducing redundant route entries.
Additionally, Dragonfly's do_ifconfig_ipv4() code is now shared with NetBSD's, rather than FreeBSD's.
---
M src/openvpn/route.c
M src/openvpn/tun.c
2 files changed, 210 insertions(+), 130 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/21/721/12
src/openvpn/route.c +208 -128
@@ -42,6 +42,7 @@#include "options.h" #include "networking.h" #include "integer.h" +#include "openvpn.h" #include "memdbg.h"
@@ -1396,6 +1397,7 @@ }gc_free (&gc); } +void setenv_routes_ipv6 (struct env_set *es,const struct route_ipv6_list *rl6) {
@@ -1472,6 +1474,37 @@ }#endif +static bool +is_gateway_needed_ipv4 (const struct route_ipv4 *r4, +const struct route_gateway_info *rgi, +const struct tuntap *tt) +{ +#ifndef _WIN32 +/* server told us which interface to use; pass gateway if it gave one */ +if (rgi && (rgi->flags &RGI_IFACE_DEFINED ) && rgi->iface[0 ] !=0 ) + { +if (rgi->flags &RGI_ADDR_DEFINED && r4->gateway !=0 ) + { +return true; + } + } +#endif + +/* TAP is an L2 device, so for destinations that are not explicitly +* on-link the kernel needs a gateway so it can ARP/ND for the +* MAC address. We make an exception only when the user explicitly sets +* metric 0, which is taken as a request for an on-link “route to +* interface” (no gateway). This keeps parity with the IPv6 code. +*/ +if (tt->type ==DEV_TYPE_TAP + && !((r4->flags &RT_METRIC_DEFINED ) && r4->metric ==0 )) + { +return true; + } + +return false; +} + bool add_route(struct route_ipv4 *r, const struct tuntap *tt, unsigned int flags, const struct route_gateway_info *rgi, /* may be NULL */
@@ -1503,28 +1536,7 @@ goto done; } -#ifndef _WIN32 -/* server told us which interface to use; pass gateway if it gave one */ -if (rgi && (rgi->flags &RGI_IFACE_DEFINED ) && rgi->iface[0 ] !=0 ) - { -if (rgi->flags &RGI_ADDR_DEFINED && r->gateway !=0 ) - { - gateway_needed = true; - } - } -#endif - -/* TAP is an L2 device, so for destinations that are not explicitly -* on-link the kernel needs a gateway so it can ARP/ND for the -* MAC address. We make an exception only when the user explicitly sets -* metric 0, which is taken as a request for an on-link “route to -* interface” (no gateway). This keeps parity with the IPv6 code. -*/ -if (tt->type ==DEV_TYPE_TAP - && !((r->flags &RT_METRIC_DEFINED ) && r->metric ==0 )) - { - gateway_needed = true; - } + gateway_needed =is_gateway_needed_ipv4 (r, rgi, tt);if (gateway_needed && r->gateway ==0 ) {
@@ -1537,18 +1549,21 @@ goto done; } -#if defined(TARGET_LINUX ) -const char *iface = tt->actual_name; +#if !defined(_WIN32) && !defined(TARGET_SOLARIS ) \ + && !defined(TARGET_AIX ) +const char *device = tt->actual_name;if (!gateway_needed && rgi && (rgi->flags &RGI_IFACE_DEFINED ) && rgi->iface[0 ] !=0 )/* vpn server special route */ { - iface = rgi->iface; + device = rgi->iface; } +#endif +#if defined(TARGET_LINUX )int metric =-1 ;if (is_on_link (is_local_route, flags, rgi)) { - iface = rgi->iface; + device = rgi->iface; }if (r->flags &RT_METRIC_DEFINED )
@@ -1560,7 +1575,7 @@ status =RTA_SUCCESS ;int ret =net_route_v4_add (ctx, &r->network,netmask_to_netbits2 (r->netmask), gateway_needed ? &r->gateway :NULL , - iface, r->table_id, metric); + device, r->table_id, metric);if (ret == -EEXIST ) {msg (D_ROUTE ,"NOTE: Linux route add command failed because route exists" );
@@ -1577,7 +1592,7 @@if (rgi) { -snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, rgi->iface); +snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, device); }else {
@@ -1672,7 +1687,7 @@bool ret =openvpn_execve_check (&argv, es,0 ,"ERROR: Solaris route add command failed" ); status = ret ?RTA_SUCCESS :RTA_ERROR ; -#elif defined(TARGET_FREEBSD ) +#elif defined(TARGET_FREEBSD ) || defined(TARGET_DRAGONFLY )argv_printf (&argv,"%s add" ,ROUTE_PATH );
@@ -1683,31 +1698,18 @@ }#endif -argv_printf_cat (&argv,"-net %s %s %s" , network, gateway, netmask); - -/* FIXME -- add on-link support for FreeBSD */ - -argv_msg (D_ROUTE , &argv); -bool ret =openvpn_execve_check (&argv, es,0 ,"ERROR: FreeBSD route add command failed" ); - status = ret ?RTA_SUCCESS :RTA_ERROR ; - -#elif defined(TARGET_DRAGONFLY) - -argv_printf (&argv,"%s add" ,ROUTE_PATH ); - -#if 0 -if (r->flags &RT_METRIC_DEFINED ) +if (gateway_needed) { -argv_printf_cat (&argv,"-rtt %d" , r->metric); +argv_printf_cat (&argv,"-net %s %s %s" , network, gateway, netmask); } -#endif - -argv_printf_cat (&argv,"-net %s %s %s" , network, gateway, netmask); - -/* FIXME -- add on-link support for Dragonfly */ +else + { +argv_printf_cat (&argv,"-net %s -iface %s" , network, device); + }argv_msg (D_ROUTE , &argv); -bool ret =openvpn_execve_check (&argv, es,0 ,"ERROR: DragonFly route add command failed" ); +bool ret =openvpn_execve_check (&argv, es,0 , +"ERROR: BSD route add command failed" ); status = ret ?RTA_SUCCESS :RTA_ERROR ;#elif defined(TARGET_DARWIN)
@@ -1730,7 +1732,14 @@ }else { -argv_printf_cat (&argv,"-net %s %s %s" , network, gateway, netmask); +if (gateway_needed) + { +argv_printf_cat (&argv,"-net %s %s %s" , network, gateway, netmask); + } +else + { +argv_printf_cat (&argv,"-net %s -interface %s" , network, device); + } }argv_msg (D_ROUTE , &argv);
@@ -1748,9 +1757,14 @@ }#endif -argv_printf_cat (&argv,"-net %s %s -netmask %s" , network, gateway, netmask); - -/* FIXME -- add on-link support for OpenBSD/NetBSD */ +if (gateway_needed) + { +argv_printf_cat (&argv,"-net %s %s -netmask %s" , network, gateway, netmask); + } +else + { +argv_printf_cat (&argv,"-net %s -netmask %s -link -iface %s" , network, netmask, device); + }argv_msg (D_ROUTE , &argv);bool ret =openvpn_execve_check (&argv, es,0 ,"ERROR: OpenBSD/NetBSD route add command failed" );
@@ -1827,6 +1841,47 @@ } } +static bool +is_gateway_needed_ipv6 (const struct route_ipv6 *r6, +const struct tuntap *tt, +const char *network) +{ +#ifndef _WIN32 +if (r6->iface !=NULL )/* VPN server special route */ + { +if (!IN6_IS_ADDR_UNSPECIFIED (&r6->gateway)) + { +return true; + } + } +#endif + +/* +* Filter out routes which are essentially no-ops +* (not currently done for IPv6) +*/ + +/* On "tun" interface, we never set a gateway if the operating system +* can do "route to interface" - it does not add value, as the target +* dev already fully qualifies the route destination on point-to-point +* interfaces. OTOH, on "tap" interface, we must always set the +* gateway unless the route is to be an on-link network +*/ +if (tt->type ==DEV_TYPE_TAP + && !((r6->flags &RT_METRIC_DEFINED ) && r6->metric ==0 )) + { +return true; + } + +if (ipv6_net_contains_host (&tt->local_ipv6, tt->netbits_ipv6, &r6->gateway)) + { +msg (D_ROUTE ,"Ignoring gateway in VPN subnet for route %s/%d" , network, r6->netbits); +return false; + } + +return false; +} +bool add_route_ipv6 (struct route_ipv6 *r6,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx)
@@ -1842,22 +1897,12 @@struct argv argv =argv_new ();struct gc_arena gc =gc_new (); -#ifndef _WIN32 -const char *device = tt->actual_name; -if (r6->iface !=NULL )/* vpn server special route */ - { - device = r6->iface; -if (!IN6_IS_ADDR_UNSPECIFIED (&r6->gateway)) - { - gateway_needed = true; - } - } -#endif -route_ipv6_clear_host_bits (r6);const char *network =print_in6_addr (r6->network,0 , &gc);const char *gateway =print_in6_addr (r6->gateway,0 , &gc); + gateway_needed =is_gateway_needed_ipv6 (r6, tt, network); +#if defined(TARGET_DARWIN ) || defined(TARGET_FREEBSD ) || defined(TARGET_DRAGONFLY ) \ || defined(TARGET_OPENBSD ) || defined(TARGET_NETBSD )
@@ -1875,6 +1920,15 @@ }#endif +#if !defined(_WIN32) + +const char *device = tt->actual_name; +if (r6->iface !=NULL ) + { + device = r6->iface; + } +#endif +#ifndef _WIN32msg (D_ROUTE ,"add_route_ipv6(%s/%d -> %s metric %d) dev %s" , network, r6->netbits, gateway, r6->metric, device);
@@ -1883,22 +1937,6 @@ r6->metric, r6->adapter_index ? r6->adapter_index : tt->adapter_index);#endif -/* -* Filter out routes which are essentially no-ops -* (not currently done for IPv6) -*/ - -/* On "tun" interface, we never set a gateway if the operating system -* can do "route to interface" - it does not add value, as the target -* dev already fully qualifies the route destination on point-to-point -* interfaces. OTOH, on "tap" interface, we must always set the -* gateway unless the route is to be an on-link network -*/ -if (tt->type ==DEV_TYPE_TAP && !((r6->flags &RT_METRIC_DEFINED ) && r6->metric ==0 )) - { - gateway_needed = true; - } -if (gateway_needed &&IN6_IS_ADDR_UNSPECIFIED (&r6->gateway)) { msg(M_WARN,
@@ -1913,6 +1951,7 @@#if defined(TARGET_LINUX )int metric =-1 ; +if ((r6->flags &RT_METRIC_DEFINED ) && (r6->metric >0 )) { metric = r6->metric;
@@ -2008,21 +2047,21 @@bool ret =openvpn_execve_check (&argv, es,0 ,"ERROR: MacOS X route add -inet6 command failed" ); status = ret ?RTA_SUCCESS :RTA_ERROR ; -#elif defined(TARGET_OPENBSD ) +#elif defined(TARGET_OPENBSD ) || defined(TARGET_NETBSD ) -argv_printf (&argv,"%s add -inet6 %s -prefixlen %d %s" ,ROUTE_PATH , network, r6->netbits, - gateway); +argv_printf (&argv,"%s add -inet6 %s -prefixlen %d " ,ROUTE_PATH , network, r6->netbits); + +if (gateway_needed) + { +argv_printf_cat (&argv,"%s" , gateway); + } +else + { +argv_printf_cat (&argv,"-link -iface %s" , device); + }argv_msg (D_ROUTE , &argv); -bool ret =openvpn_execve_check (&argv, es,0 ,"ERROR: OpenBSD route add -inet6 command failed" ); - status = ret ?RTA_SUCCESS :RTA_ERROR ; - -#elif defined(TARGET_NETBSD ) - -argv_printf (&argv,"%s add -inet6 %s/%d %s" ,ROUTE_PATH , network, r6->netbits, gateway); - -argv_msg (D_ROUTE , &argv); -bool ret =openvpn_execve_check (&argv, es,0 ,"ERROR: NetBSD route add -inet6 command failed" ); +bool ret =openvpn_execve_check (&argv, es,0 ,"ERROR: OpenBSD/NetBSD route add -inet6 command failed" ); status = ret ?RTA_SUCCESS :RTA_ERROR ;#elif defined(TARGET_AIX )
@@ -2080,6 +2119,21 @@#endif int is_local_route; +#if defined(TARGET_DARWIN ) || defined(TARGET_LINUX ) \ + || defined(TARGET_FREEBSD ) || defined(TARGET_DRAGONFLY ) \ + || defined(TARGET_OPENBSD ) || defined(TARGET_NETBSD ) + +bool gateway_needed =is_gateway_needed_ipv4 (r, rgi, tt); + +#if !defined(TARGET_OPENBSD ) && !defined(TARGET_NETBSD ) +const char *device = tt->actual_name; +if (!gateway_needed && rgi && (rgi->flags &RGI_IFACE_DEFINED ) && rgi->iface[0 ] !=0 )/* vpn server special route */ + { + device = rgi->iface; + } +#endif +#endif +if ((r->flags & (RT_DEFINED |RT_ADDED )) != (RT_DEFINED |RT_ADDED )) {return ;
@@ -2106,12 +2160,19 @@#if defined(TARGET_LINUX ) metric =-1 ; + +if (is_on_link (is_local_route, flags, rgi)) + { + device = rgi->iface; + } +if (r->flags &RT_METRIC_DEFINED ) { metric = r->metric; } -if (net_route_v4_del (ctx, &r->network,netmask_to_netbits2 (r->netmask), &r->gateway,NULL , +if (net_route_v4_del (ctx, &r->network,netmask_to_netbits2 (r->netmask), + gateway_needed ? &r->gateway :NULL , device, r->table_id, metric) <0 ) {
@@ -2165,19 +2226,21 @@argv_msg (D_ROUTE , &argv);openvpn_execve_check (&argv, es,0 ,"ERROR: Solaris route delete command failed" ); -#elif defined(TARGET_FREEBSD ) +#elif defined(TARGET_FREEBSD ) || defined(TARGET_DRAGONFLY ) -argv_printf (&argv,"%s delete -net %s %s %s" ,ROUTE_PATH , network, gateway, netmask); +argv_printf (&argv,"%s delete" ,ROUTE_PATH ); + +if (gateway_needed) + { +argv_printf_cat (&argv,"-net %s %s %s" , network, gateway, netmask); + } +else + { +argv_printf_cat (&argv,"-net %s -iface %s" , network, device); + }argv_msg (D_ROUTE , &argv); -openvpn_execve_check (&argv, es,0 ,"ERROR: FreeBSD route delete command failed" ); - -#elif defined(TARGET_DRAGONFLY ) - -argv_printf (&argv,"%s delete -net %s %s %s" ,ROUTE_PATH , network, gateway, netmask); - -argv_msg (D_ROUTE , &argv); -openvpn_execve_check (&argv, es,0 ,"ERROR: DragonFly route delete command failed" ); +openvpn_execve_check (&argv, es,0 ,"ERROR: BSD route delete command failed" );#elif defined(TARGET_DARWIN )
@@ -2188,7 +2251,16 @@ }else { -argv_printf (&argv,"%s delete -net %s %s %s" ,ROUTE_PATH , network, gateway, netmask); +argv_printf (&argv,"%s delete " ,ROUTE_PATH ); + +if (gateway_needed) + { +argv_printf_cat (&argv,"-net %s %s %s" , network, gateway, netmask); + } +else + { +argv_printf_cat (&argv,"-net %s -interface %s" , network, device); + } }argv_msg (D_ROUTE , &argv);
@@ -2196,7 +2268,16 @@#elif defined(TARGET_OPENBSD ) || defined(TARGET_NETBSD ) -argv_printf (&argv,"%s delete -net %s %s -netmask %s" ,ROUTE_PATH , network, gateway, netmask); +argv_printf (&argv,"%s delete " ,ROUTE_PATH ); + +if (gateway_needed) + { +argv_printf_cat (&argv,"-net %s %s -netmask %s" , network, gateway, netmask); + } +else + { +argv_printf_cat (&argv,"-net %s -netmask %s" , network, netmask); + }argv_msg (D_ROUTE , &argv);openvpn_execve_check (&argv, es,0 ,"ERROR: OpenBSD/NetBSD route delete command failed" );
@@ -2250,23 +2331,16 @@#if !defined(TARGET_LINUX )const char *gateway;#endif -#if !defined(TARGET_SOLARIS ) -bool gateway_needed = false; +#if defined(TARGET_DARWIN ) || defined(TARGET_LINUX ) \ + || defined(TARGET_FREEBSD ) || defined(TARGET_DRAGONFLY ) +const char *device = tt->actual_name;if (r6->iface !=NULL )/* vpn server special route */ { device = r6->iface; - gateway_needed = true; } (void )device;/* unused on some platforms */ -/* if we used a gateway on "add route", we also need to specify it on -* delete, otherwise some OSes will refuse to delete the route -*/ -if (tt->type ==DEV_TYPE_TAP && !((r6->flags &RT_METRIC_DEFINED ) && r6->metric ==0 )) - { - gateway_needed = true; - }#endif #endif
@@ -2278,6 +2352,15 @@ gateway =print_in6_addr (r6->gateway,0 , &gc);#endif +#if defined(TARGET_DARWIN ) || defined(TARGET_LINUX ) || defined(TARGET_FREEBSD ) \ + || defined(TARGET_DRAGONFLY ) || defined(TARGET_OPENBSD ) || defined(TARGET_NETBSD ) +/* if we used a gateway on "add route", we also need to specify it on +* delete, otherwise some OSes will refuse to delete the route +*/ +bool gateway_needed = false; + gateway_needed =is_gateway_needed_ipv6 (r6, tt, network); +#endif +#if defined(TARGET_DARWIN ) || defined(TARGET_FREEBSD ) || defined(TARGET_DRAGONFLY ) \ || defined(TARGET_OPENBSD ) || defined(TARGET_NETBSD )
@@ -2362,20 +2445,17 @@argv_msg (D_ROUTE , &argv);openvpn_execve_check (&argv, es,0 ,"ERROR: MacOS X route delete -inet6 command failed" ); -#elif defined(TARGET_OPENBSD ) +#elif defined(TARGET_OPENBSD ) || defined(TARGET_NETBSD ) -argv_printf (&argv,"%s delete -inet6 %s -prefixlen %d %s" ,ROUTE_PATH , network, r6->netbits, - gateway); +argv_printf (&argv,"%s delete -inet6 %s -prefixlen %d" ,ROUTE_PATH , network, r6->netbits); + +if (gateway_needed) + { +argv_printf_cat (&argv,"%s" , gateway); + }argv_msg (D_ROUTE , &argv); -openvpn_execve_check (&argv, es,0 ,"ERROR: OpenBSD route delete -inet6 command failed" ); - -#elif defined(TARGET_NETBSD ) - -argv_printf (&argv,"%s delete -inet6 %s/%d %s" ,ROUTE_PATH , network, r6->netbits, gateway); - -argv_msg (D_ROUTE , &argv); -openvpn_execve_check (&argv, es,0 ,"ERROR: NetBSD route delete -inet6 command failed" ); +openvpn_execve_check (&argv, es,0 ,"ERROR: OpenBSD/NetBSD route delete -inet6 command failed" );#elif defined(TARGET_AIX )
src/openvpn/tun.c +2 -2
@@ -1383,7 +1383,7 @@ add_route(&r, tt, 0, NULL, es, NULL); } -#elif defined(TARGET_NETBSD) +#elif defined(TARGET_NETBSD) || defined(TARGET_DRAGONFLY)in_addr_t remote_end =INADDR_ANY ;/* for "virtual" subnet topology */ if (tun_p2p)
@@ -1466,7 +1466,7 @@ add_route(&r, tt, 0, NULL, es, NULL); } -#elif defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) +#elif defined(TARGET_FREEBSD)/* example: ifconfig tun2 10.2.0.2 10.2.0.1 mtu 1450 netmask 255.255.255.255 up */ if (tun_p2p)/* point-to-point tun */
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I87777e74b1fd34781e1d72c9f994eb84f39d800c
Gerrit-Change-Number: 721
Gerrit-PatchSet: 12
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Attention is currently required from: flichtenheld, ordex, plaisthos.
mrbff has posted comments on this change by mrbff. ( http://gerrit.openvpn.net/c/openvpn/+/721?usp=email )
Change subject: route: extended logic to omit gateway when unnecessary
......................................................................
Patch Set 12:
(6 comments)
File src/openvpn/route.h:
http://gerrit.openvpn.net/c/openvpn/+/721/comment/0a1b545d_f913bbc8?usp=email :
PS11, Line 274: bool add_route_ipv6(struct route_ipv6 *r, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx, const bool is_multipoint);
Quoted 1 line
The naming here and the usage seem to disagree. […]
Done
File src/openvpn/route.c:
http://gerrit.openvpn.net/c/openvpn/+/721/comment/aaa6380b_66ab5947?usp=email :
PS11, Line 1811: /* FIXME -- add on-link support for Dragonfly */
Quoted 1 line
Has this been really tested on DragonFly BSD?
i tested on the first patch but i tested again the #12 on 6.4.2 and found also a bug with the ifconfig, i fixed just moving from #if defined(TARGET_FREEBSD) || defined (TARGET_DRAGONFLY) code to #if defined(TARGET_NETBSD) || defined (TARGET_DRAGONFLY) code in do_ifconfig_ipv4(). Here the logs:
master:
2025-10-20 13:36:42 PUSH: Received control message: 'PUSH_REPLY,route-gateway 10.23.100.1,topology subnet,ping 5,ping-restart 30,ifconfig 10.23.100.2 255.255.255.0,peer-id 0,cipher AES-256-GCM,protocol-flags cc-exit tls-ekm dyn-tls-crypt,tun-mtu 1500' 2025-10-20 13:36:42 OPTIONS IMPORT: --ifconfig/up options modified 2025-10-20 13:36:42 OPTIONS IMPORT: route-related options modified 2025-10-20 13:36:42 OPTIONS IMPORT: tun-mtu set to 1500 2025-10-20 13:36:42 TUN/TAP device tun0 exists previously, keep at program end 2025-10-20 13:36:42 TUN/TAP device /dev/tun0 opened 2025-10-20 13:36:42 tun/tap device [tun0] opened
2025-10-20 13:36:42 /sbin/ifconfig tun0 10.23.100.2/24 mtu 1500 up ifconfig: ioctl (SIOCAIFADDR): Destination address required 2025-10-20 13:36:42 FreeBSD ifconfig failed: external program exited with error status: 1 2025-10-20 13:36:42 Exiting due to fatal error
patchset #12:
2025-10-20 13:43:42 PUSH: Received control message: 'PUSH_REPLY,route-gateway 10.23.100.1,topology subnet,ping 5,ping-restart 30,ifconfig 10.23.100.2 255.255.255.0,peer-id 0,cipher AES-256-GCM,protocol-flags cc-exit tls-ekm dyn-tls-crypt,tun-mtu 1500' 2025-10-20 13:43:42 OPTIONS IMPORT: --ifconfig/up options modified 2025-10-20 13:43:42 OPTIONS IMPORT: route-related options modified 2025-10-20 13:43:42 OPTIONS IMPORT: tun-mtu set to 1500 2025-10-20 13:43:42 TUN/TAP device tun0 exists previously, keep at program end 2025-10-20 13:43:42 TUN/TAP device /dev/tun0 opened 2025-10-20 13:43:42 tun/tap device [tun0] opened
2025-10-20 13:43:42 /sbin/ifconfig tun0 10.23.100.2 10.23.100.1 mtu 1500 netmask 255.255.255.0 up 2025-10-20 13:43:42 /sbin/route add -net 10.23.100.0 -iface tun0
add net 10.23.100.0: gateway tun0
2025-10-20 13:43:42 Initialization Sequence Completed
If you have any thought about it or something to suggest (or some particular test) please feel free to share
http://gerrit.openvpn.net/c/openvpn/+/721/comment/b2bc803a_7e364e02?usp=email :
PS11, Line 1600: && !( (r4->flags & RT_METRIC_DEFINED) && r4->metric == 0 ) )
Quoted 1 line
how does the metric play into needing a gateway or not?
Done
http://gerrit.openvpn.net/c/openvpn/+/721/comment/2a5d88e2_1d00ff0a?usp=email :
PS11, Line 1607: return true;
Quoted 1 line
There should at least be some idea/comment in the source code as well. […]
Done
http://gerrit.openvpn.net/c/openvpn/+/721/comment/85295ff5_ccdfe664?usp=email :
PS11, Line 1898: }
Quoted 1 line
Has this been tested on Open and NetBSD?
it was already tested from the first patch but i retested the latest patch on dradonfly 6.4.2, openbsd 7.7, freebsd 14.3, netbsd 10.0 and MacOS sonoma
http://gerrit.openvpn.net/c/openvpn/+/721/comment/0b6b4458_7d49c544?usp=email :
PS11, Line 2010: {
Quoted 1 line
I think this duplicates the code that was publicly accessible in https://gerrit.openvpn. […]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/721?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I87777e74b1fd34781e1d72c9f994eb84f39d800c
Gerrit-Change-Number: 721
Gerrit-PatchSet: 12
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Tue, 21 Oct 2025 14:10:18 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: plaisthos <[email protected]...>
Comment-In-Reply-To: ordex <[email protected]...>